<?php

/**
 * 资金账户
 */

namespace app\member\api;

use \app\member\api\MemberApi;

class FinanceApi extends MemberApi {

    /**
     * 财务记录
     */
    public function index() {

        $pageLimit = $this->data['limit'] ? $this->data['limit'] : 10;

        $where = [];
        $type = $this->data['type'];

        if($type == 1) {
            $where['A.type'] = 1;
        }
        if($type == 2) {
            $where['A.type'] = 0;
        }

        $accountInfo = target('member/PayAccount')->getWhereInfo([
            'A.user_id' => $this->userId
        ]);

        $where['A.account_id'] = $accountInfo['account_id'];

        $model = target('member/PayLog');
        $count = $model->countList($where);
        $pageData = $this->pageData($count, $pageLimit);
        $list = $model->loadList($where, $pageData['limit'], 'log_id desc');

        if ($list) {
            $this->success('ok', [
                'data' => $list,
                'pageData' => [
                    'pageLimit' => $pageLimit,
                    'limit' => count($list),
                    'page' => $pageData['page'],
                    'totalPage' => $pageData['totalPage']
                ]
            ]);
        } else {
            $this->error('暂无更多记录', 404);
        }

    }

}